package com.ahp.action;

import java.io.IOException;
import java.io.PrintWriter;

import org.omg.CORBA.Request;

import com.ahp.bean.Factor;
import com.ahp.service.FactorService;

public class FactorAction extends CommonActionSupport {
	private static final long serialVersionUID = 1L;
	private Factor factor;
	private FactorService factorService;
	public Factor getFactor() {
		return factor;
	}
	public void setFactor(Factor factor) {
		this.factor = factor;
	}
	public FactorService getFactorService() {
		return factorService;
	}
	public void setFactorService(FactorService factorService) {
		this.factorService = factorService;
	}
	
	public String addFirstFactor(){
		PrintWriter out;
		try {
			out = getResponse().getWriter();
			if(factorService.addFirstFactor(factor)){
				out.print("suc");
			}else{
				out.print("fal");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return NONE;
	}
	
	public String findFirstFactor(){
	  getRequest().setAttribute("list",factorService.findFirstFactor(Integer.parseInt(getRequest().getParameter("id"))));
		return SUCCESS;
	}
	
	public String viewSecondFactor(){
		  getRequest().setAttribute("list",factorService.findSecondFactor(Integer.parseInt(getRequest().getParameter("id"))));
		  getRequest().setAttribute("factor",getRequest().getParameter("name"));
			return SUCCESS;
		}
	
	public String viewFirstFactor(){
		  getRequest().setAttribute("list",factorService.findFirstFactor(Integer.parseInt(getRequest().getParameter("id"))));
		  getRequest().setAttribute("modlueName",getRequest().getParameter("modlueName"));
		  return SUCCESS;
		}
	
	public String removeFactor(){
		PrintWriter out;
		try {
			out = getResponse().getWriter();
			if(factorService.removeFactor(Integer.parseInt(getRequest().getParameter("id")))){
				out.print("suc");
			}else{
				out.print("fal");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
	
}
